<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        /* li:nth-child(2n){
           background-color: red;
        }
        li:nth-child(2n+1){
            background-color: blue;
        }
        li:hover{
            background-color: aquamarine;
        } */
        .orangeBg{
            background-color: orange;
        }
        .greenBg{
            background-color: green;
        }
    </style>
</head>
<body>
    <ul>
        <li>aaa</li>
        <li>aaa</li>
        <li>aaa</li>
        <li>aaa</li>
        <li>aaa</li>
        <li>aaa</li>
        <li>aaa</li>
        <li>aaa</li>
    </ul>
    <script>
        var lis=document.getElementsByTagName("li");

        for(var i=0;i<lis.length;i++){
             if(i%2==0){//i除以2，余数为0，偶数
                lis[i].className='orangeBg';
             }else{//奇数
                lis[i].className='greenBg';
             }

            lis[i].onmouseover=function(){
                //改变颜色,添加了style,style优先
                this.style.backgroundColor="pink";
            } 

            lis[i].onmouseout=function(){
                //删除颜色，没有了style,class的优先
                this.style.backgroundColor="";
            } 
        }
    </script>
</body>
</html>